import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import './hot_word.dart';
import './search_result.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
import './search_his.dart';
import 'dart:io';

class SearchPage extends StatelessWidget {
  final Widget child;
  TextEditingController _textEditingController = new TextEditingController();

  SearchPage({Key key, this.child}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: AppBar(
        title: Container(
          width: ScreenUtil().setWidth(500),
          height: ScreenUtil().setHeight(80),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(50),
          ),
          child: TextField(// 输入框
            controller: _textEditingController,
            textInputAction: TextInputAction.search,
            decoration: InputDecoration(
              contentPadding: EdgeInsets.all(10),
              border: InputBorder.none,
              fillColor: Colors.black12,
              filled: true,
              hintText: '请输入关键词',
              suffixIcon: IconButton(
                icon: Icon(Icons.clear),
                onPressed: (){
                  _textEditingController.clear();
                },
              )
            ),
            onSubmitted: (str){// 输入框搜索方法
              if(str==''){
                Fluttertoast.showToast(
                  msg: '请输入搜索词',
                  toastLength: Toast.LENGTH_SHORT,
                  gravity: ToastGravity.BOTTOM,
                  timeInSecForIos: 2,
                  backgroundColor: Theme.of(context).primaryColor,
                  textColor: Colors.white,
                  fontSize: 16.0
                );
                return;
              }
              
              Navigator.push(context, MaterialPageRoute(
                builder: (context){
                  return SearchResult(keyword: str,);
                }
              ));
            },
          ),
        )
      ),
      body: Column(
        children: <Widget>[
          Container(
            width: ScreenUtil().setWidth(750),
            padding: EdgeInsets.all(8),
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(width: 1,color: Colors.black12))
            ),
            child: Text('大家都在搜',style: TextStyle(color: Colors.black54),),
          ),
          HotWord(),
        ],
      ),
    );
  }

}